package com.hjx.windowtool;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;

public class CreateMenu {
	public static void main(String[] args) {
		String classpath = System.getProperty("user.dir");
		File file = new File(classpath+"\\"+"src\\main\\java");
		ArrayList<File> list = new ArrayList<File>();
		for (File file2 : file.listFiles()) {
			findFiles(list, file2);
		}
		List<String> listClassName=new ArrayList<String>();
		for (File file2 : list) {
			String cn = file2.getAbsolutePath().replace(file.getAbsolutePath(), "").substring(1).replace("\\", ".").replace(".java", "");
			System.out.println(cn);
			listClassName.add(cn);
		}
		listClassName.sort((e1,e2)->e1.compareTo(e2));
		File file2 = new File(classpath+"\\"+"src\\main\\resources");
		try {
			if(!file2.exists()||!file2.isDirectory()) {
				file2.mkdirs();
			}
			Files.write(new File(classpath+"\\"+"src\\main\\resources\\classes.txt").toPath(), listClassName, Charset.forName("UTF-8"));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public static void findFiles(List<File> list,File f) {
		if(f.isDirectory()) {
			for (File file : f.listFiles()) {
				if (file.isDirectory()) {
					findFiles(list, file);
				}else {
					list.add(file);
				}
			}
		}else {
			list.add(f);
		}
	}
}
